<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <base th:href="${#servletContext.getContextPath()+'/'}">

    <script type="text/javascript" src="https://cdn.goeasy.io/goeasy-2.0.13.min.js"></script>

    <script type="text/javascript" th:inline="javascript">

        // 获取到订单id
        var oid = [[${order.id}]];
    </script>

    <script typ|e="text/javascript">

        // 1、初始化,建立连接
        var goeasy  = GoEasy.getInstance({
            host:"hangzhou.goeasy.io",  //若是新加坡区域：singapore.goeasy.io
            appkey:"BC-1f35eadfecb44ba2838fe648c638f71f",
            modules:['pubsub']//根据需要，传入‘pubsub’或'im’，或数组方式同时传入
        });

        // 2、建立连接
        goeasy.connect({
            onSuccess: function () {  //连接成功
                console.log("GoEasy connect successfully.") //连接成功
            },
            onFailed: function (error) { //连接失败
                console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
            },
            onProgress:function(attempts) { //连接或自动重连中
                console.log("GoEasy is connecting", attempts);
            }
        });

        // 3.订阅消息
        var pubsub = goeasy.pubsub;
        pubsub.subscribe({
            channel: oid,// 订阅的通道
            onMessage: function (message) {
                var msg = message.content;
                console.log("Channel:" + message.channel + " content:" + msg);

                // 微信已经调用了异步回调接口
                if(msg == "ok"){
                    // 跳转到一个支付成功页面
                    // location.href = "http://xxxx/cotroller?oid="+oid;
                    // location.href = "http://www.baidu.com";
                    location.href = "http://localhost/shop-home";
                }
            },
            onSuccess: function () {
                console.log("Channel订阅成功。");
            },
            onFailed: function (error) {
                console.log("Channel订阅失败, 错误编码：" + error.code + " 错误信息：" + error.content)
            }
        });


    </script>
</head>
<body>

<h3 th:text="|订单编号:${order.id}|"></h3>
<h3 th:text="|订单价格:${order.totalPrice}|"></h3>
<h3>请扫码支付</h3>
<img width="300" height="300" th:src="|http://localhost/shop-pay/weiXinPayController/createQREncode?url=${codeUrl}|">


</body>
</html>